package muse.schedule;

import java.util.ArrayList;
import java.util.Calendar;

public class Schedule {
	private ArrayList<Calendar> days;
	private Calendar time;
	private Frequency freq;
	public Schedule(Frequency f, Calendar when) {
		days = new ArrayList<Calendar>();
		days.add(when);
		freq = f;
		time = when;
	}
	public int getHour() {
		return time.get(Calendar.HOUR);
	}
	public int getMinute() {
		return time.get(Calendar.MINUTE);
	}
	public boolean isScheduled(Calendar day) {
		Calendar first = days.get(0);
		switch(freq) {
			case CUSTOM:	return days.contains(day);
			case DAILY: 	return true;
			case BIDAILY:	return first.get(Calendar.DATE) % 2 == day.get(Calendar.DATE) % 2;
			case WEEKLY:	return first.get(Calendar.DAY_OF_WEEK) == day.get(Calendar.DAY_OF_WEEK);
			case BIWEEKLY:	return first.get(Calendar.WEEK_OF_YEAR) % 2 == day.get(Calendar.WEEK_OF_YEAR) % 2;
			case MONTHLY: 	return first.get(Calendar.DATE) == day.get(Calendar.DATE);
			case BIMONTHLY: return first.get(Calendar.MONTH) % 2 == day.get(Calendar.MONTH) % 2 && first.get(Calendar.DATE) == day.get(Calendar.DATE);
			case ANNUAL: 	return first.get(Calendar.DAY_OF_YEAR) == day.get(Calendar.DAY_OF_YEAR);
			case WEEKDAYS:	return day.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY && day.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY;
			case WEEKENDS:	return day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
			default:		return false;
		}
	}
	public void toggleDay(Calendar day) {
		if(days.contains(day))
			days.remove(day);
		else days.add(day);
	}
}
